// 工厂，根据传入的品牌实例化对应适配器
import { PlatformStrategy } from './PlatformStrategy';
import { XiaomiStrategy } from './xiaomi/XiaomiStrategy';
import { MideaStrategy } from "./midea/MideaStrategy";
import {MockThirdParty} from "../mock/MockThirdParty";
import * as path from 'path';
import * as fs from 'fs';

// 读取 brand-config.json
const brandConfigPath = path.resolve(__dirname, '../../brand-config.json');
const BrandConfig = JSON.parse(fs.readFileSync(brandConfigPath, 'utf-8'));

export interface BrandStrategy {
  exchangeToken(code: string): Promise<{ access_token: string; expires_in: number }>;
  revokeToken(token: string): Promise<boolean>;
  refreshToken(userId: string, oldToken: string): Promise<{ access_token: string; expires_in: number }>;
  getDeviceList(accessToken: string): Promise<{ did: string; name: string; type: string; online: boolean}[]>;
  subscribeDevice?(accessToken: string, deviceId: string): Promise<void>;
  revokeDeviceSubscription?(userId: string, did: string):Promise<void>;
  controlDevice?(did:string, operation: string, value:any, accessToken: string): Promise<{ status: { result: 1 | 0; isSameState: 0 | 1 } }>;
}

export function getStrategy(brand: string): PlatformStrategy {
  switch (brand) {
    case 'xiaomi':
      return new XiaomiStrategy();

    case 'midea':
      return new MideaStrategy();

    default:
      throw new Error(`Unsupported brand: ${brand}`);
  }
}

